﻿using System;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.DC;
using DevExpress.Data.Filtering;
using DevExpress.Persistent.Base;
using System.Collections.Generic;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;

namespace aztall.Module.BusinessObjects
{
	[DefaultClassOptions, XafDefaultProperty("DomainCode"), NavigationItem("Administration")]
	[ImageName("BO_Organization")]
	public class Domain : RootObject
	{
		protected string _DomainCode;

		public Domain(Session session)
				: base(session)
		{
			_DomainCode = Env.CurrentDomainCode;
		}
		public Domain() : base(null)
		{ }
		public override void AfterConstruction()
		{
			base.AfterConstruction();
		}
		[RuleRequiredField(DefaultContexts.Save, SkipNullOrEmptyValues = false)]
		[RuleUniqueValue(DefaultContexts.Save, CriteriaEvaluationBehavior = CriteriaEvaluationBehavior.InTransaction)]
		[Indexed(Unique = false)]
		public string DomainCode
		{
			get { return _DomainCode; }
			set { SetPropertyValue(nameof(DomainCode), ref _DomainCode, value); }
		}
		[Size(SizeAttribute.Unlimited), VisibleInListView(true)]
		[ImageEditor(ListViewImageEditorMode = ImageEditorMode.PictureEdit,
				DetailViewImageEditorMode = ImageEditorMode.PictureEdit,
				ListViewImageEditorCustomHeight = 40,
				DetailViewImageEditorFixedHeight = 72,
			DetailViewImageEditorFixedWidth = 128,
			ImageSizeMode = ImageSizeMode.Zoom)]
		public byte[] Image
		{
			get { return GetPropertyValue<byte[]>("Image"); }
			set { SetPropertyValue<byte[]>("Image", value); }
		}
		[Association("Domain_User", UseAssociationNameAsIntermediateTableName = true), DevExpress.Xpo.DisplayName("Users"), VisibleInDetailView(true)]
		[Delayed]
		public XPCollection<User> Users
		{
			get
			{
				return GetCollection<User>(nameof(Users));
			}
		}
	}
}
